package yatan.common.utility;

public final class EncodeUtility {
    private EncodeUtility() {
    }

    public static String convertEncodedCharacters(String code) {
        StringBuffer sb = new StringBuffer(code);
        int startPos = sb.indexOf("&#");
        int endPos;
        while (startPos > -1) {
            endPos = sb.indexOf(";", startPos);
            if (endPos > startPos) {
                try {
                    int value = Integer.parseInt(sb.substring(startPos + 2, endPos), 10);
                    sb.replace(startPos, endPos + 1, Character.toString((char) value));
                } catch (NumberFormatException e) {
                    // simply ignore
                }
            }

            startPos = sb.indexOf("&#", startPos + 1);
        }
        return code = sb.toString();
    }
}
